package javabasics.concurrent.guardedsuspension;

import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * 服务端进程
 *
 * @Author suxiaoxiao
 * @Date 2019/6/16 13:42
 * @Version 1.0
 */
public class ServerThread extends Thread {

    private RequestQueue requestQueue;

    public ServerThread(RequestQueue requestQueue, String name) {
        super(name);
        this.requestQueue = requestQueue;
    }

    @Override
    public void run() {
        while (true) {
            // 得到请求
            final Request request = requestQueue.getReqeust();

            try {
                // 模拟请求处理过程
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(Thread.currentThread().getName() + " handles" + request);
        }
    }

}
